﻿@using Apps.Models.Sys;
@{
	ViewBag.Title = "Index";
	Layout = "~/Views/Shared/_Layout.cshtml";
}
<style>
	.l-btn-text {
		padding-left: 45px;
	}

	.l-btn {
		background: #91edf3;
		margin: 0px 5px;
	}

		.l-btn:hover {
			background: #02e6f5;
		}

	.mvctool {
		padding: 5px;
	}
</style>
<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>

<div class="mvctool">
	<input id="txtQuery" type="text" class="searchText">
	<a id="btnQuery" style="float: left;" class="l-btn l-btn-plain"><span class="l-btn-left"><span class="l-btn-text icon-search">查询</span></span></a><div class="datagrid-btn-separator"></div>
	<a id="btnCreate" style="float: left;" class="l-btn l-btn-plain"><span class="l-btn-left"><span class="l-btn-text icon-add">新增</span></span></a><div class="datagrid-btn-separator"></div>
	<a id="btnEdit" style="float: left;" class="l-btn l-btn-plain"><span class="l-btn-left"><span class="l-btn-text icon-edit">编辑</span></span></a><div class="datagrid-btn-separator"></div>
	<a id="btnDetails" style="float: left;" class="l-btn l-btn-plain"><span class="l-btn-left"><span class="l-btn-text icon-alltype">详细</span></span></a><div class="datagrid-btn-separator"></div>
	<a id="btnDelete" style="float: left;" class="l-btn l-btn-plain"><span class="l-btn-left"><span class="l-btn-text icon-remove">删除</span></span></a><div class="datagrid-btn-separator"></div>
	<a id="btnExport" style="float: left;" class="l-btn l-btn-plain"><span class="l-btn-left"><span class="l-btn-text icon-moveup">导出</span></span></a>
	<a id="btnReload" style="float: left;" class="l-btn l-btn-plain"><span class="l-btn-left"><span class="l-btn-text icon-reload">刷新</span></span></a>
</div>

<table id="List"></table>

<script src="~/Scripts/Mvc/jquery.easyui.plus.js"></script>
<script type="text/javascript">
	//加载table
	$(function () {
		$('#List').datagrid({
			url: '/SysSample/GetList',
			width: $(window).width() - 30,
			methord: 'post',
			height: $(window).height() - 35,
			fitColumns: true,
			sortName: 'Id',
			sortOrder: 'desc',
			idField: 'Id',
			pageSize: 10,
			pageList: [10, 20, 30, 40, 50],
			pagination: true,
			striped: true, //奇偶行是否区分
			singleSelect: true,//单选模式
			rownumbers: true,//行号
			columns: [[
				{ field: 'Id', title: 'ID', width: 80, align: 'center' },
				{ field: 'Name', title: '名称', width: 120, align: 'center' },
				{ field: 'Age', title: '年龄', width: 80, align: 'center' },
				{ field: 'Bir', title: '生日', width: 80, align: 'center', function() { } },
				{ field: 'Photo', title: '照片', width: 150, align: 'center' },
				{ field: 'Note', title: '说明', width: 60, align: 'center' },
				{ field: 'CreateTime', title: '创建时间', width: 80, align: 'center' }
			]]
		});
	});

	//ifram 返回
	function frameReturnByClose() {
		$("#modalwindow").window('close');
	}
	//iframe 返回并刷新
	function frameReturnByReload(flag) {
		if (flag)
			$("#List").datagrid('load');
		else
			$("#List").datagrid('reload');
	}
	//输出信息
	function frameReturnByMes(mes) {
		$.messageBox5s('提示', mes);
	}
	$(function () {

		$("#btnCreate").click(function () {
			$("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0'' src='/SysSample/Create'></iframe>");
			$("#modalwindow").window({ title: '新增', width: 700, height: 400, iconCls: 'icon-add' }).window('open');
		});
		$("#btnEdit").click(function () {
			var row = $('#List').datagrid('getSelected');
			if (row != null) {
				$("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='/SysSample/Edit?id=" + row.Id + "'></iframe>");
				$("#modalwindow").window({ title: '编辑', width: 700, height: 430, iconCls: 'icon-edit' }).window('open');
			} else { $.messageBox5s('提示', '请选择要操作的记录'); }
		});
		$("#btnDetails").click(function () {
			var row = $('#List').datagrid('getSelected');
			if (row != null) {

				$("#modalwindow").html("<iframe width='100%' height='98%' scrolling='no' frameborder='0' src='/SysSample/Details?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
				$("#modalwindow").window({ title: '详细', width: 500, height: 300, iconCls: 'icon-details' }).window('open');
			} else { $.messageBox5s('提示', '请选择要操作的记录'); }
		});
		$("#btnQuery").click(function () {
			var queryStr = $("#txtQuery").val();
			//如果查询条件为空默认查询全部
			if (queryStr == null) {
				queryStr = "%";
			}
			$('#List').datagrid({
				url: '/SysSample/GetList?queryStr=' + encodeURI(queryStr)
			});

		});
		$("#btnDelete").click(function () {
			var row = $('#List').datagrid('getSelected');
			if (row != null) {
				$.messager.confirm('提示', '确定删除', function (r) {
					if (r) {
						$.post("/SysSample/Delete?id=" + row.Id, function (data) {
							if (data.type == 1)
								$("#List").datagrid('load');
							$.messageBox5s('提示', data.message);
						}, "json");

					}
				});
			} else { $.messageBox5s('提示', '请选择要操作的记录'); }
		});
	});

	function GetGuid() {
		var guid = "";
		for (var i = 1; i <= 32; i++) {
			var n = Math.floor(Math.random() * 16.0).toString(16);
			guid += n;
			if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
				guid += "-";
		}
		return guid;
	}
</script>
